package com.lanou.beautifulwardrobe.home.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.Log;

import com.lanou.beautifulwardrobe.entify.TagItem;
import com.lanou.beautifulwardrobe.factory.HomeFragmentFactory;

import java.util.List;

/**
 * Created by dllo on 15/10/21.
 */
public class HomeViewPagerAdapter extends FragmentPagerAdapter {
    private List<TagItem> datas;

    public void addData(List<TagItem> items) {
        datas = items;
        Log.i("lanou", datas.size() + "++++");
        for (TagItem t : datas) {
            Log.i("lanou", t.getTag_title() + "&&&");
        }
        notifyDataSetChanged();
    }

    public HomeViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        //   Log.i("lanou", position + "#####");
        //return HomeFragment.getHomeFragment(position);
       String itemTitle= datas.get(position).getTag_title();
        String id=new String();
         id +=datas.get(position).getId();
        return HomeFragmentFactory.createFragment(position,itemTitle,id);
    }

    @Override
    public int getCount() {

        return datas != null && datas.size() > 0 ? datas.size() : 0;
        // return titles.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        //  Log.i("lanou",position+"======");
        return datas != null && datas.size() > 0 ? datas.get(position).getTag_title() : "无";
        // return titles[position];
    }
}

